
/*
   tsAPI Distribution
   ts_zoom Class

   TrueSpectra Inc, 2002
   Code by: Kevin Martin
*/


function ts_zoom(baseImage,max_width,max_height,isSecure,baseImage2) {
	if( this.zoomi == null ) {
		this.DynLayer = DynLayer;
		this.DynLayer( null,0,0,max_width,max_height );

		this.zoom_width  = max_width;
		this.zoom_height = max_height;
	
		//If 2 params then different background image
		this.baseImageF = baseImage;
		if( ""+baseImage2 == "undefined" ) baseImage2 = null;
		this.baseImageB = baseImage2 || baseImage;

		if( ""+isSecure == "undefined" ) this.isSecure = false;
		this.isSecure = false || isSecure;

		this.spin_slider = null;
		this.colorsw = null;
		this.colorize = false;
		this.isSpin = false;
		this.loaded = false;
		this.delay = 20;


		this.zoomi = new zoom_image(this.baseImageF,this.zoom_width,this.zoom_height,this.isSecure,this.baseImageB);

		this.addChild(this.zoomi);
		this.zoomi.moveTo(0,0);

		this.colorsw = new color_swatch(color_swatch.HORIZONTAL,10,0,1,false,false);
		this.colorsw.setVisible(false);
		this.colorsw.addTargetImage(this.zoomi.bgimg);
		this.colorsw.addTargetImage(this.zoomi.dbimg,true);

		var zoomload = new EventListener(this);
			zoomload.onresizedone = function(e) {
				o = e.getTarget();
				o.loaded = true;
				o.setSize( o.zoomi.w,o.zoomi.h); //+(o.isSpin==true?o.spin_slider.h:0) );	//NO UI FOR SPIN
				e.setBubble(false);
		};
		this.zoomi.addEventListener(zoomload);

		this.zoomi.fetchBaseImages(this.zoomi.maxWait);
	};
}; 

ts_zoom.prototype = new DynLayer;
ts_zoom.prototype.zoomi = null;


ts_zoom.prototype.addToPage = function(absolutePos) {

//	if( ""+absolutePos=="true" ) 	{ DynAPI.document.addChild(this); }
//	else				{ DynAPI.document.addInflowChild(this); };

	this.zoomi.initPageSettings(absolutePos);

	if( !(is.ns4 || is.ns5 || is.ns6 || is.ie4) ) setTimeout(this+'.checkPreload();',this.delay);
};

ts_zoom.prototype.checkPreload = function() {
	var a = ""+this.zoomi.initComplete;
	if( !this.zoomi.initComplete || a == "undefined" ) {
		setTimeout(this+'.checkPreload();',this.delay);
		return;
	};

	if( this.zoomi.initRGNZone!=null ) this.zoomi.ZoomSet( this.zoomi.initRGNZone, true );
	this.zoomi.showImages();

	if( !this.zoomi.ZoomError ) {
		if( this.isSpin==true) {
			if( this.zoomi.navbox ) this.spin_slider.addTargetImage(this.zoomi.navbox.nvimg);	//could be a problem
			this.spin_slider.setSize(this.zoomi.w,13);
			this.spin_slider.start_loadLowRes();
		};
		if( this.colorize == true )	{ 
			if( this.zoomi.navbox ) this.colorsw.addTargetImage(this.zoomi.navbox.nvimg);		//could be a problem
			this.colorsw.start_loadLowRes(); 
		};

	};
};

ts_zoom.prototype.addInformation = function(str) {	this.zoomi.addInformation(str); };
ts_zoom.prototype.setHelpPage = function(str,w,h) {	this.zoomi.setHelpPage(str,w,h); };
ts_zoom.prototype.initialRGN = function(rgn) {		if( !this.zoomi.initComplete ) this.zoomi.ZoomInit(rgn,"rgn"); };
ts_zoom.prototype.initialRGNN = function(rgn) {		if( !this.zoomi.initComplete ) this.zoomi.ZoomInit(rgn,"rgnn"); };
ts_zoom.prototype.setRGN = function(rgn) {		this.zoomi.ZoomSet(rgn,"rgn"); };
ts_zoom.prototype.setRGNN = function(rgn) {		this.zoomi.ZoomSet(rgn,"rgnn"); };
ts_zoom.prototype.zoomOut = function() {		this.zoomi.ZoomOut(); };
ts_zoom.prototype.zoomIn = function() {			this.zoomi.ZoomIn( Math.round(this.zoomi.img_width/2), Math.round(this.zoomi.img_height/2) ); };
ts_zoom.prototype.reset = function() {			this.zoomi.ZoomReset(); };
ts_zoom.prototype.enableZoomBar = function() {		if( !this.zoomi.initComplete ) this.zoomi.enableZoomBar(); };
ts_zoom.prototype.disableZoomBar = function() {		if( !this.zoomi.initComplete ) this.zoomi.disableZoomBar(); };
ts_zoom.prototype.setMaxZoom = function(zoomLevels,amount) {	if( !this.zoomi.initComplete ) this.zoomi.setMaxZoom(zoomLevels, amount); };
ts_zoom.prototype.enableNav = function(position) {	if( !this.zoomi.initComplete ) this.zoomi.enableNav(position); };
ts_zoom.prototype.pan = function(direction,amount) {	this.zoomi.manualPan(direction,amount); };
ts_zoom.prototype.setBackground = function(bgColor) {
	if( !this.zoomi.initComplete ) {
		if( ""+bgColor != "undefined" && ""+bgColor.length > 6 ) {
			this.zoomi.setBackground(bgColor.substr(bgColor.length-6)); 
		} else {
			this.zoomi.setBackground(bgColor); 
		};
	};
};

ts_zoom.prototype.setBorder = function(sz,bgColor) {	
	if( !this.zoomi.initComplete ) { 
		this.setSize( this.w+sz*2,this.h+sz*2); 
		if( ""+bgColor != "undefined" && ""+bgColor.length > 6 ) {
			this.zoomi.setBorder(sz,bgColor.substr(bgColor.length-6)); 
		} else {
			this.zoomi.setBorder(sz,bgColor); 
		};
	}; 
};

ts_zoom.prototype.changeColor = function(sLayer,sRGB) {	
	if( ""+sRGB != "undefined" && ""+sRGB.length > 6 ) {
		this.colorsw.changeColor_All(sRGB.substr(sRGB.length-6),sLayer);
	} else {
		this.colorsw.changeColor_All(sRGB,sLayer); 
	};
};


ts_zoom.prototype.spinReplaceRule1 = function(pre,post,inc) {
	if( this.isSpin == true )		{ this.spin_slider.addReplaceRule1(pre,post,inc); };
};

ts_zoom.prototype.spinReplaceRule2 = function(pre,num,inc) {
	if( this.isSpin == true )		{ this.spin_slider.addReplaceRule2(pre,num,inc); };
};

ts_zoom.prototype.addColor = function(sLayer,sRGB) {		//Preload Color
	if( !this.zoomi.initComplete ) {
		this.colorize = true;
		if( ""+sRGB != "undefined" && ""+sRGB.length > 6 ) {
			this.colorsw.addColor(sRGB.substr(sRGB.length-6),sLayer);
		} else {
			this.colorsw.addColor(sRGB,sLayer);
		};
	};
};


ts_zoom.prototype.enableUI = function(imgFolder,offset,spacing) {
	if( !this.zoomi.initComplete ) {
		this.setSize( this.w,this.h+20-Math.min(20,offset)+1 ); 
		this.zoomi.enableUI(imgFolder,offset,spacing);
		if( this.isSpin == true ) { this.spin_slider.changeUI(imgFolder) };
	};
};

ts_zoom.prototype.addSpin = function(frames,buttonType) {
	if( !this.zoomi.initComplete ) {
		this.isSpin = true;
		this.buttonType = buttonType || 0;
		this.zoomi.setButtonType(buttonType);

		this.spin_slider = new spin_ScrollBar(spin_ScrollBar.HORIZONTAL,frames,1,false,null,this.zoomi);
		this.spin_slider.setVisible(false);
		this.spin_slider.addTargetImage(this.zoomi.bgimg,false);
		this.spin_slider.addTargetImage(this.zoomi.dbimg,true);
//		this.addChild(this.spin_slider);		//NO UI SO DISABLED

		var zsListener = new EventListener(this);
		zsListener.shift = 0;
		zsListener.onpanSpecial = function(e) {
			var o = e.getTarget();
			var moveAmount = o.zoomi.imgCover.x-this.shift;
			this.shift = o.zoomi.imgCover.x;
			o.spin_slider.setPos((o.spin_slider.getPos()+o.spin_slider.getMaxPos()*10+moveAmount)%o.spin_slider.getMaxPos());
			o.spin_slider.changeFrame(o.spin_slider.getPos(),false);	
		};
		zsListener.onpanDoneSpecial = function(e) {
			var o = e.getTarget();
			this.shift = 0;
			o.spin_slider.changeFrame(o.spin_slider.getPos(),true);
		};
		this.zoomi.addEventListener(zsListener);


		if( this.colorize==true ) {
			var colorload = new EventListener(this);
				colorload.oncolorchange = function(e) {
					e.getTarget().spin_slider.start_loadLowRes();
				};
			this.colorsw.addEventListener(colorload);
		};
	};
};

ts_zoom.prototype.spin = function( frames ) {
	if( this.isSpin == true && parseInt(frames)!=0 ) this.spin_slider.spin(parseInt(frames));
};

ts_zoom.prototype.advanced = function( zoomAmount,tiles,percision ) {
	if( !this.zoomi.initComplete ) this.zoomi.advanced( zoomAmount,tiles,percision );
};
